﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace park.Login
{
    public partial class login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public override void ProcessRequest(HttpContext context)
        {
            string sheade = context.Request.Headers["X-Requested-With"];//XMLHttpRequest jQuery
            if (sheade == "XMLHttpRequest")
            {
                var req = context.Request;
                var res = context.Response;
                if (req.Params["AjaxCheckLogin"] != null)
                {
                    res.Write(!UserOnline ? "0" : "1");
                    res.End();
                }
                else if (req.Params["AjaxLogout"] != null)
                {
                    UserName = UserPwd = null;
                }
            }
            else
            {
                base.ProcessRequest(context);
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();
            string pwd = txtPwd.Text;
            if (name == "")
            {
                name = "demo";
            }
            if (pwd == "")
            {
                pwd = "demo";
            }
            pwd = EncryptToMD5(pwd);
            //调用ws认证

            //认证后
            UserName = name;
            UserPwd = pwd;
            Response.Redirect("../index/index.aspx");
        }
    }
}